# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=snoopy-ng
pkgver=128.eac73f5
pkgrel=6
groups=('blackarch' 'blackarch-drone' 'blackarch-exploitation'
        'blackarch-sniffer')
pkgdesc='A distributed, sensor, data collection, interception, analysis, and
visualization framework.'
arch=('any')
url='https://github.com/sensepost/snoopy-ng'
license=('custom')
depends=('python2' 'autossh' 'python2-psutil' 'libpcap' 'python2-sqlalchemy'
         'ppp' 'python2-requests'  'python2-smspdu' 'mitmproxy'
         'python2-httplib2' 'python2-pyinotify' 'python2-netifaces'
         'python2-dnslib' 'python2-dpkt' 'python2-pylibpcap' 'python2-pyserial'
         'aircrack-ng' 'tcpdump' 'sqlite3' 'iw' 'python2-pybluez'
         'python2-flask' 'gpsd' 'python2-dateutil' 'python2-publicsuffix')
makedepends=('git')
source=("git+https://github.com/sensepost/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir"/usr/share/snoopy-ng/{includes,plugins,transforms,uat,setup}
  install -dm 755 "$pkgdir/usr/share/doc/$pkgname"
  install -dm 755 "$pkgdir/usr/share/sslstrip-snoopy"

  cp -a LICENSE.txt "$pkgdir/usr/share/$pkgname/"
  install -Dm 644 LICENSE.txt "$pkgdir/usr/share/licenses/snoopy-ng/LICENSE.txt"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md TODO.txt
  install -Dm 644 includes/* "$pkgdir/usr/share/$pkgname/includes/"
  cp -a --no-preserve=ownership setup/* "$pkgdir/usr/share/$pkgname/setup/"
  cp -a --no-preserve=ownership plugins/* "$pkgdir/usr/share/$pkgname/plugins/"
  install -Dm 644 uat/* "$pkgdir/usr/share/$pkgname/uat/"
  install -Dm 644 transforms/* "$pkgdir/usr/share/$pkgname/transforms/"
  install -Dm 755 snoopy.py "$pkgdir/usr/share/$pkgname/snoopy.py"

  echo "sqlite:///usr/share/snoopy-ng/snoopy.db" \
    > "$pkgdir/usr/share/snoopy-ng/transforms/db_path.conf"

  cd setup/sslstripSnoopy/
  cp -a --no-preserve=ownership * "$pkgdir/usr/share/sslstrip-snoopy/"

  cat > "$pkgdir/usr/bin/snoopy" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 snoopy.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/snoopy"

  cat > "$pkgdir/usr/bin/snoopy-auth" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 includes/auth_handler.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/snoopy-auth"

  cat > "$pkgdir/usr/bin/sslstrip-snoopy" << EOF
#!/bin/sh
cd /usr/share/sslstrip-snoopy
python2 sslstrip.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/sslstrip-snoopy"
}

